﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;

namespace DAL
{
   public  class wuyiDAL
    {
        DBHelper db = new DBHelper();
        public DataTable wuyishow()   //显示物遗表的dgv
        {
            string sql = string.Format("select * from wuyi where delstatus=1");
            return db.cx(sql);
        }
        public DataTable cxwuyi(string wuyiname,int wuyiall,int wuyitake)  //物遗模糊查询
        {
            string sql = string.Format("select * from wuyi where 1>0 and delstatus = '1' ");
            if (!string.IsNullOrEmpty(wuyiname))
            {
                sql += string.Format("and yname like '%{0}%' ",wuyiname);
            }
            if (wuyiall>0)
            {
                sql += string.Format(" or delstatus = '0' ");
            }
            if (wuyitake==2)
            {
                sql += string.Format("and Cstatus ='已领取'");
            }
            return db.cx(sql);
        }
        public int wuyiAdd(string yname,string pickplace,string pickuname,string pickutel,string Ctime,string Cstatus)   //添加物遗表的dgv
        {
            string sql = string.Format("INSERT INTO [dbo].[wuyi]([yname],[pickplace],[pickuname],[pickutel],[Ctime],[Cstatus],[delstatus])VALUES('{0}','{1}','{2}','{3}','{4}','{5}','{6}')",yname,pickplace, pickuname,pickutel,Ctime, Cstatus, 1);
            return db.zsg(sql);
        }   
        public int wuyimodify(string yname, string pickplace, string pickuname, string pickutel, string Ctime, string Cstatus ,int id)
        {
            String sql = string.Format("UPDATE [dbo].[wuyi]SET [yname] = '{0}',[pickplace] = '{1}',[pickuname] = '{2}',[pickutel] = '{3}',[Ctime] = '{4}',[Cstatus] = '{5}'WHERE id='{6}'", yname, pickplace, pickuname, pickutel, Ctime, Cstatus,id );
            return db.zsg(sql);
        }
        public DataTable wumodifyShow(int id)    //用户的修改赋值去主页面
        {
            string sql = string.Format("select * from wuyi where id='{0}'", id);
            return db.cx(sql);
        }
        public int wydel(int id)    // 删除用户
        {
            String sql = string.Format("update wuyi set delstatus ='{0}' where id='{1}' ", 0, id);
            return db.zsg(sql);
        }
    }
}
